package com.zmn.oms.zmn.business.impl.chan;

import com.alibaba.fastjson.JSON;
import com.zmn.oms.model.entity.chan.FacadeMessageEvent;
import com.zmn.oms.model.entity.chan.FacadeMessageEventError;
import com.zmn.oms.services.interfaces.chan.FacadeMessageEventErrorService;
import com.zmn.oms.zmn.business.interfaces.chan.FacadeMessageEventErrorBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 类描述：
 *
 * @author lhl
 * @date 2021/01/06 16:12
 */
@Service("facadeMessageEventErrorBService")
public class FacadeMessageEventErrorBServiceImpl implements FacadeMessageEventErrorBService {

    @Autowired
    private FacadeMessageEventErrorService facadeMessageEventErrorService;

    /**
     * 保存渠道门户消息事件错误
     * @param facadeMessageEvent
     * @param errorMsg
     */
    @Override
    public void saveFacadeMessageEventError(FacadeMessageEvent facadeMessageEvent, String errorMsg) {
        FacadeMessageEventError eventError = new FacadeMessageEventError();
        eventError.setFacadeId(facadeMessageEvent.getFacadeId());
        eventError.setErrorMsg(errorMsg.length() > 480 ? errorMsg.substring(0, 480) : errorMsg);

        FacadeMessageEvent eventCopy = new FacadeMessageEvent();
        eventCopy.setFacadeId(facadeMessageEvent.getFacadeId());
        eventCopy.setClueId(facadeMessageEvent.getClueId());
        eventCopy.setChannelId(facadeMessageEvent.getChannelId());
        eventCopy.setTag(facadeMessageEvent.getTag());
        eventCopy.setFun(facadeMessageEvent.getFun());
        eventCopy.setAge(facadeMessageEvent.getAge());
        eventCopy.setMessageNo(facadeMessageEvent.getMessageNo());
        eventCopy.setOpTime(facadeMessageEvent.getOpTime());
        eventError.setEventSummary(JSON.toJSONString(eventCopy));

        facadeMessageEventErrorService.save(eventError);
    }
}
